﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Streambolics.Gui;

namespace Streambolics.App.Gpl
{
    public partial class OlvModuleDetails : StandardForm
    {
        private ComputingModule _Module;

        public static void Open (ComputingModule aModule)
        {
            OlvModuleDetails f = new OlvModuleDetails ();
            f.Module = aModule;
            f.Show (StandardForm.MainForm);
        }

        public OlvModuleDetails ()
        {
            InitializeComponent ();
        }

        protected override void OnFormClosing (FormClosingEventArgs e)
        {
            Module = null;
            base.OnFormClosing (e);
        }

        public ComputingModule Module
        {
            get
            {
                return _Module;
            }
            set
            {
                if (_Module != value)
                {
                    if (_Module != null)
                    {
                        _Module.StatusChanged -= new ComputingModuleStatusChangedEventHandler (_Module_StatusChanged);
                    }
                    _Module = value;
                    if (_Module != null)
                    {
                        _Module.StatusChanged += new ComputingModuleStatusChangedEventHandler (_Module_StatusChanged);
                    }
                    properties.SelectedObject = _Module;
                    list.Module = _Module;
                    Redisplay ();
                }
            }
        }

        void _Module_StatusChanged (object Sender, ComputingModuleStatusChangedEventArgs evt)
        {
            Redisplay ();
        }

        private void Redisplay ()
        {
            properties.Refresh ();
            Text = _Module != null ? _Module.Name : "No module selected";
            label_StatusText.Text = _Module != null ? _Module.StatusText : "";
        }
    }
}
